from django.db import models


class Add(models.Model):
    x = models.IntegerField()
    y = models.IntegerField()
    result = models.IntegerField(blank=True, null=True)

    def __str__(self):
        return '{}+{}'.format(self.x, self.y)

    # signals trigger switch
    _disable_signals = False

    def save_without_signals(self):
        """
        This allows for updating the model from code running inside post_save()
        signals without going into an infinite loop:
        refer: https://stackoverflow.com/questions/10840030/django-post-save-preventing-recursion-without-overriding-model-save
        """
        self._disable_signals = True
        self.save()
        self._disable_signals = False

